<script setup name="HomeBoxes">
const props = defineProps({
  boxList: {
    type: Array,
    default: () => []
  }
})

const boxes = ref([])
watch(() => props.boxList, () => {
  props.boxList.forEach((item) => {
    boxes.value[item.id] = item.introduction
  })
})

const handleEnter = (box_id, link_desc) => {
  boxes.value[box_id] = link_desc
}

</script>

<template>
  <div class="boxes px-4 grid sm:grid-cols-1 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
    <div
      v-for="(item, index) in props.boxList"
      :key="index"
      class="box m-2 px-2 py-5 bg-gray-900 bg-opacity-40 rounded-xl"
    >
      <h4 class="title text-xl pb-4">{{ item.title }}</h4>
      <h6 class="text-sm truncate">{{ boxes[item.id] || '&nbsp;' }}</h6>
      <div class="box-scroll h-40 grid sm:grid-cols-2 xl:grid-cols-3">
        <a
          v-for="(link, link_index) in item.links"
          :key="link_index"
          class="my-4 text-sm"
          :href="link.link"
          target="__blank"
          @mouseenter="handleEnter(item.id, link.description)"
        >{{ link.title }}</a>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
@import "../../assets/styles/_mixin";
.box {
  text-align: var(--box-link-align);
  background-color: var(--box-background-color);
  &:hover {
    background-color: var(--box-background-hover-color);
  }
  .title {
    color: var(--box-title-color);
  }
  .box-scroll {
    @include scroll-y(6, #24272e);
  }
  a {
    color: var(box-link-color);
    &:hover {
      color: var(--box-link-hover-color);
    }
  }
}
</style>
